/**
 * @(#)InputValidator.java        1.0 4/11/12
 * 
 * Copyright (c) 2012 public static droid main
 * Georgia Institute of Technology, Atlanta, GA
 * All rights reserved.
 */
package edu.gatech.oad.publicstaticdroidmain.taskmanager.model;


/**
 * Validates inputs from the UI to make sure they are formatted
 * correctly.  The methods in this class are static.
 * 
 * @version 1.0 3/25/12
 * @author Raheel Merali
 *
 */
public class InputValidator {
    
    /* Regular expression to validate an email address */
    private static final String EMAIL_ADDRESS_REGEX = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    
    private InputValidator() { }
    
    /**
     * Determines whether the specified String is a valid email address.
     * 
     * @param emailAddress the email address
     * @return true if the email address is valid; false otherwise
     */
    public static boolean isValidEmailAddress(String emailAddress) {
	if (emailAddress == null) {
	    return false;
	}
	
	if (emailAddress.matches(EMAIL_ADDRESS_REGEX)) {
	    return true;
	}
	
	return false;
    }
    
    /**
     * Determines whether the specified String is a valid username.
     * 
     * @param username the username
     * @return true if the username is valid; false otherwise
     */
    public static boolean isValidUsername(String username) {
	if (username == null) {
	    return false;
	}
	
	if (username.length() == 0) {
	    return false;
	}
	
	if (username.contains(" ")) {
	    return false;
	}
	
	return true;
    }
    
    /**
     * Determines whether the specified String is a valid password.
     * 
     * @param password the password
     * @return true if the password is valid; false otherwise
     */
    public static boolean isValidPassword(String password) {
	if (password == null) {
	    return false;
	}
	
	if (password.length() == 0) {
	    return false;
	}
	
	return true;
    }
    
    /**
     * Determines whether the specified String is a valid real name.
     * 
     * @param realName the real name
     * @return true if the real name is valid; false otherwise
     */
    public static boolean isValidRealName(String realName) {
	if (realName == null) {
	    return false;
	}
	
	if (realName.length() == 0) {
	    return false;
	}
	
	if (realName.startsWith(" ") || realName.endsWith(" ")) {
	    return false;
	}
	
	return true;
    }
    
}
